package com.mall.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mall.entity.ShoppingCart;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author ShouPeng
 * @since 2024-01-15
 * 购物车mapper
 */
@Repository
@Mapper
public interface ShoppingCartMapper extends BaseMapper<ShoppingCart> {

    /**
     * 添加购物车已经存在的商品的购买数量
     * @param count 数量
     * @return bool
     */
    @Update("update mall_shopping_cart set goods_count = goods_count + #{count} where goods_id = #{goodsId} and user_id = #{userId}")
    Boolean addShoppingCartItemCount(String goodsId, Integer count,String userId);


    /**
     * 查询购物车
     * @return cart_items
     */
    @Select("select mg.goods_id as goods_id,msc.user_id,shopping_cart_id,goods_price,goods_name,goods_count,goods_cover from mall_shopping_cart msc " +
            "left join mall_goods mg on msc.goods_id = mg.goods_id where msc.user_id = #{userId}")
    List<ShoppingCart> queryShoppingCart(String userId);

    /**
     * 根据购物车id查询购物车信息
     * @param userId
     * @param shoppingCartIds
     * @return
     */
//    @Select("select mg.goods_id as goods_id,msc.user_id,shopping_cart_id,goods_price,goods_name,goods_count,goods_cover from mall_shopping_cart msc " +
//            "left join mall_goods mg on msc.goods_id = mg.goods_id where msc.user_id = #{userId} and msc.shopping_cart_id IN (#{shoppingCartIds})")
    List<ShoppingCart> queryShoppingCartByCartIds(String userId,List<Integer> shoppingCartIds);
}
